/* 
 * File:   ConnectionDefinition.hpp
 * Author: Faisal
 *
 * Created on April 27, 2012, 8:39 PM
 *
 * Description:
 *			This class will store the connection information for all the available data sources. Application needs to add connections at the start up using options like:
 *			1. Read from a text file and load the connections
 *			2. Provide hard coded connection information from code
 *			3. Either do the step 1 or 2 for the one connection and store all other encrypted connection strings in the database
 */

#ifndef CONNECTIONDEFINITION_DL
#define	CONNECTIONDEFINITION_DL

#include "../Include/Shared.hpp"
#include <Common/Include/ConnectionSourceName.hpp>
#include <Common/Include/ConnectionSourceType.hpp>


#include <queue>
#include <map>

using Supetronix::PersistO::Common::ConnectionSourceName;
using Supetronix::PersistO::Common::ConnectionSourceType;
using std::string;

namespace Supetronix
{
	namespace PersistO
	{
		namespace DL
		{
                    class ConnectionDefinition
                    {
                    public:
						/*
						*	Methods
						*/

						//Add methods will take the parameters to initialize the connection definition object and store it internal cache
                        static void Add(ConnectionSourceName sourceName, ConnectionSourceType sourceType, string serverName, string userID, string password, string databaseName, int minPoolSize = 0, int maxPoolSize = 10);

						//Get the connection definition from the internal cache by using the connection source name
                        static const ConnectionDefinition* Get(ConnectionSourceName sourceName);
                        
						/*
						*	Properties
						*/

						//Underlying connection source type
                        const ConnectionSourceType& SourceType() { return _sourceType; }

						//Maximum connection pool size
                        const int& MaxPoolSize() const { return _maxPoolSize; }

						//Name of the source server
                        const string& ServerName() const { return _serverName; }

						//User name to connect to source
                        const string& UserID() const { return _userID; }

						//password for user validation
                        const string& Password() const { return _password; }

						//name of the database
                        const string& DatabaseName() const { return _databaseName; }                        
                        
                    private:
                        /*
						*	constructor and destructor
						*/
                        ConnectionDefinition() {}
                        
						/*
						*	Member variables
						*/
                        ConnectionSourceName _sourceName;
                        ConnectionSourceType _sourceType;
                        string _serverName;
                        string _userID;
                        string _password;
                        string _databaseName;
                        int _minPoolSize, _maxPoolSize;
                        
						//cache for storing the connection information
                        static std::map<ConnectionSourceName, ConnectionDefinition*>* _definitionStore;
                    };
                }
        }
}


#endif	/* CONNECTIONDEFINITION_HPP */

